#include <string>
#include <vector>
#include <unordered_map>
#include <iostream>
#include <algorithm>
#include <sstream>

using namespace std;

string stat_encoding(const string &str) {
  unordered_map<char, int> records;

  for (char c : str) {
    if (records.find(c) != records.end()) {
      ++records[c];
    }
    else {
      records[c] = 1;
    }
  }

  // Get all keys
  vector<char> keys;
  for (auto record : records) {
    keys.push_back(record.first);
  }

  sort(keys.begin(), keys.end());
  string result;
  ostringstream oss;

  for (char c : keys) {
    int n = records[c];
    oss << n << c;  
  }

  return oss.str();
}

int main(int argc, char const *argv[])
{
  /* code */
  cout << stat_encoding("CCABB") << endl;
  return 0;
}
